package com.example.a2209_mianshi.widget

import android.content.Context
import android.view.LayoutInflater
import android.view.View
import com.bigkoo.convenientbanner.holder.Holder
import com.example.a2209_mianshi.databinding.ItemMallHomeBannerChildBinding
import com.example.a2209_mianshi.ui.mall.model.MallBanner

class MallBannerHolder(
    private val withBtn: Boolean = true,
    private val onBookingClick: ((MallBanner) -> Unit)? = null
) : Holder<MallBanner> {
    private var mBinding: ItemMallHomeBannerChildBinding? = null

    override fun createView(context: Context): View {
        mBinding = ItemMallHomeBannerChildBinding.inflate(LayoutInflater.from(context))
        return mBinding!!.root
    }

    override fun UpdateUI(context: Context, position: Int, item: MallBanner) {
        mBinding?.item = item
        mBinding?.withBtn = withBtn && item.type == "in" && item.productType == "vehicle"

//        mBinding?.btnBooking?.setOnClickListener {
//            onBookingClick?.invoke(item)
//        }
//        mBinding?.btnBuy?.setOnClickListener {
//            // 立即订购
//            // ToastUtils.showLong(context, "立即订购：${item.dataId}")
//            GoodsDetailActivity.jump(item.dataId ?: 0L)
//        }
//        mBinding?.picBanner?.setOnClickListener {
//            /**banner跳转*/
//            //AnalyticsEventMgr.getInstance().bannerAnalytics(item, show = true, click = true, "skl_app_home_pop")
//            if (!item.adAddr.isNullOrEmpty())
//                AnalyticsEventMgr.getInstance().bannerAnalytics(item, show = true, click = true, item.adAddr)
//            // 立即订购
//            if (item.type == "in") {
//                GoodsDetailActivity.jump(item.dataId ?: 0L)
//            } else {
//                CommonWebActivity.jump(
//                    item.name ?: "", item.url ?: "",
//                    useWebTitle = item.name.isNullOrEmpty()
//                )
//            }
//        }
    }
}

/**仅有图片banner*/
//class ImageBannerHolder(private val isRound: Boolean = true, private val paddingHorizontal: Int = 0) : Holder<MallBanner> {
//    private var mBinding: ItemImageBannerChildBinding? = null
//
//    override fun createView(context: Context): View {
//        mBinding = ItemImageBannerChildBinding.inflate(LayoutInflater.from(context))
//        return mBinding!!.root
//    }
//
//    override fun UpdateUI(context: Context, position: Int, item: MallBanner) {
//        mBinding?.item = item
//        mBinding?.isRound = isRound
//        mBinding?.root?.setPadding(paddingHorizontal, 0, paddingHorizontal, 0)
//    }
//}


/**俱乐部主页Banner*/
//class ClubHomeActivityBannerHolder() : Holder<ClubActivityRecommendItem> {
//    private var mBinding: ItemClubHomeActivityBannerChildBinding? = null
//
//    override fun createView(context: Context): View {
//        mBinding = ItemClubHomeActivityBannerChildBinding.inflate(LayoutInflater.from(context))
//        return mBinding!!.root
//    }
//
//    override fun UpdateUI(context: Context, position: Int, item: ClubActivityRecommendItem) {
//        mBinding?.item = item
//        mBinding?.executePendingBindings()
//    }
//}